#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <sstream>
#include <istream>
using namespace std;
class TextQuery
{
public:
void readFile(const string & filename){
    ifstream ifs(filename);
    string line;
    int linenums;
    while(getline(ifs,line)){
        //每一行存入
        _lines.push_back(line);
        string word;
        istringstream iss;
        while(iss>>word){
            _wordNumbers[word].insert(linenums);
            ++_dict[word];
        }
    }
}
void query(const string & word){
    cout << "orrurs" << _dict[word] << "times"<<endl;
    for(auto & linenumber : _wordNumbers[word]){
        cout << "(" << linenumber << ")" << _lines[linenumber - 1] <<endl;
    }
}

private:
vector<string> _lines;//存储文件内容，方便输出单词所在行
map<string, set<int> > _wordNumbers;//返回单词，单词行号
map<string, int> _dict;//单词
};


//程序测试用例
int main()
{
string queryWord("hello");

TextQuery tq;
tq.readFile("test.dat");
tq.query(queryWord);
return 0;
}


